import { Injectable } from '@angular/core';
import {Headers, RequestOptions} from '@angular/http';
import {adSystemApiUrl} from '../../../config/api';
import {HttpService} from '../../lib/service/http.service';
import {LocalStorageService} from "../../lib/service/local-storage.service";

@Injectable()
export class ActivityService {

  constructor(
    private httpService: HttpService,
    private localStorageService: LocalStorageService
  ) { }


  getActivityList(page,pageSize,keyword = '') {
    const url = `${adSystemApiUrl}/v3/member/activity_plan/list/?page=${page}&pageSize=${pageSize}&keyword=${keyword}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }


  //添加活动
  addActivityPlan(data) {
    const url = `${adSystemApiUrl}/v3/member/activity_plan/add`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
    const options = new RequestOptions({ headers: headers });
    const body = JSON.stringify(data);
    return this.httpService.httpPostAuth(url, body, options).map(res => res);
  }

  //修改活动
  editActivityPlan(data) {
    const url = `${adSystemApiUrl}/v3/member/activity_plan/edit`;
    const headers = new Headers({ 'Content-Type': 'application/json' });
    const options = new RequestOptions({ headers: headers });
    const body = JSON.stringify(data);
    return this.httpService.httpPostAuth(url, body, options).map(res => res);
  }

  //删除活动
  delActivityPlan(id) {
    const url = `${adSystemApiUrl}/v3/member/activity_plan/del`;
    const headers = new Headers({'Content-Type': 'application/json'});
    const options = new RequestOptions({headers: headers});
    const body = JSON.stringify({id: id});
    return this.httpService.httpPostAuth(url, body, options).map(res => res);
  }

  //活动详情
  getActivityInfo(id) {
    const url = `${adSystemApiUrl}/v3/member/activity_plan/info/?id=${id}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }


  //获取二维码
  getQrcode(id) {
    const url = `${adSystemApiUrl}/v3/member/activity_plan/get_activity_plan_erwei?id=${id}`;
    return this.httpService.httpGetAuth(url).map(res => res);
  }
}
